<template>
  <div>
    <h2>我是 Food 各地美食的内容</h2>
    <h3 :style="{ opacity }">一闪一闪亮晶晶</h3>
  </div>
</template>

<script>
export default {
  name: "Food",
  data() {
    return {
      opacity: 1,
    };
  },
  activated() {
    console.log("Food 组件被激活了");
    this.timer = setInterval(() => {
      console.log("定时器被执行");
      this.opacity -= 0.01;
      if (this.opacity <= 0) {
        this.opacity = 1;
      }
    }, 16);
  },
  deactivated() {
    console.log("Food 组件失活了");
    clearInterval(this.timer);
  },
};
</script>